home *** CD-ROM | disk | FTP | other *** search
/ Cream of the Crop 11 / Cream of the Crop 11-2.iso / extra / disp186b.zip / TR8900.ASM < prev    next >
Assembly Source File  |  1993-12-06  |  11KB  |  382 lines

  1. ;--------------------------------------------------------------------------
  2. ; This is file TR8900.ASM
  3. ;
  4. ; Copyright (C) 1991 DJ Delorie, 24 Kirsten Ave, Rochester NH 03867-2954
  5. ; Copyright (C) 1992 Csaba Biegl, 820 Stirrup Dr, Nashville, TN 37221
  6. ;
  7. ; This file is distributed under the terms listed in the document
  8. ; "copying.dj", available from DJ Delorie at the address above.
  9. ; A copy of "copying.dj" should accompany this file; if not, a copy
  10. ; should be available from where this file was obtained.  This file
  11. ; may not be distributed without a verbatim copy of "copying.dj".
  12. ;
  13. ; This file is distributed WITHOUT ANY WARRANTY; without even the implied
  14. ; warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
  15. ;--------------------------------------------------------------------------
  16.  
  17. include grdriver.inc
  18. cseg    segment byte public 'code'
  19.     assume  cs:cseg, ds:cseg, es:cseg, ss:nothing
  20.  
  21.  
  22. ;--------------------------------------------------------------------------
  23. ; DRIVER HEADER
  24. ;  The following entries MUST match the structure and constant
  25. ;  declarations in the file 'grdriver.h' of the GRX graphics library
  26. ;  The mode word should contain the following bitfields:
  27. ;     - the GRD_NEW_DRIVER bit set for any new format driver
  28. ;     - the adapter type field should be specified
  29. ;     - the memory size field should be specified
  30. ;     - the paging mode field should be specified
  31. ;  The mode set routine will OR in the plane bitfield as it will
  32. ;  change when different color number modes are requested.
  33. ;--------------------------------------------------------------------------
  34.  
  35.     dw    offset mode_set_routine
  36.     dw    offset paging_routine
  37. mode_W  dw    GRD_NEW_DRIVER+GRD_VGA+GRD_1024K+GRD_NO_RW
  38. ;
  39. ; The 'def_xx' fields are filled in by go32 from the corresponding
  40. ; fields of the 'GO32' environment variable
  41. ;
  42. def_tw  dw    80        ; text width
  43. def_th  dw    25        ; text height
  44. def_gw  dw    640        ; graphics width
  45. def_gh  dw    480        ; graphics height
  46. def_nc  dw    16        ; graphics colors
  47.     dw    offset driver_init_routine
  48.     dw    offset text_mode_table
  49.     dw    offset graphics_mode_table
  50.  
  51. ;
  52. ; Biggest text and graphics sizes
  53. ;
  54. Max_TW  equ    132
  55. Max_TH  equ    60
  56. Max_GWn equ    800        ; non interlaced!!!
  57. Max_GHn equ    600
  58. Max_GW  equ    1024        ; may be interlaced
  59. Max_GH  equ    768
  60.  
  61.  
  62. ;--------------------------------------------------------------------------
  63. ; TABLE OF SUPPORTED TEXT MODES
  64. ;    - keep sorted by size
  65. ;    - end with an all 0 entry
  66. ;    - BIOS field = 0xff disables it
  67. ;    - fields:
  68. ;        width,  height, colors, BIOS#+  setup_procedure_index*256
  69. ;--------------------------------------------------------------------------
  70. text_mode_table        label word
  71.     dw    80,    25,    2,    007h +  00000h
  72.     dw    40,    25,    16,    001h +  00000h
  73.     dw    80,    25,    16,    003h +  00000h
  74.     dw    80,    30,    16,    050h +  00000h
  75.     dw    80,    43,    16,    051h +  00000h
  76.     dw    80,    60,    16,    052h +  00000h
  77.     dw    132,    25,    16,    053h +  00000h
  78.     dw    132,    30,    16,    054h +  00000h
  79.     dw    132,    43,    16,    055h +  00000h
  80.     dw    132,    60,    16,    056h +  00000h
  81.     dw    0,    0,    0,    000h +  00000h
  82.  
  83.  
  84. ;--------------------------------------------------------------------------
  85. ; TABLE OF SUPPORTED GRAPHICS MODES
  86. ;    - keep sorted first by colors then by size
  87. ;    - end with an all 0 entry
  88. ;    - BIOS field = 0xff disables it
  89. ;    - fields:
  90. ;        width,  height, colors, BIOS#+  setup_procedure_index*256
  91. ;--------------------------------------------------------------------------
  92. graphics_mode_table    label word
  93.     dw    320,    200,    16,    00dh +  00000h
  94.     dw    640,    200,    16,    00eh +  00000h
  95.     dw    640,    350,    16,    010h +  00000h
  96.     dw    640,    480,    16,    012h +  00000h
  97.     dw    800,    600,    16,    05bh +  00000h
  98.     dw    1024,    768,    16,    05fh +  00000h
  99.     dw    320,    200,    256,    013h +  00000h
  100.     dw    640,    400,    256,    05ch +  00000h
  101.     dw    640,    480,    256,    05dh +  00000h
  102.     dw    800,    600,    256,    05eh +  00000h
  103.     dw    1024,    768,    256,    062h +  00000h
  104.     dw    0,    0,    0,    000h +  00000h
  105.  
  106.  
  107. ;--------------------------------------------------------------------------
  108. ; TABLE OF SPECIAL SETUP PROCEDURES
  109. ;  You may need such procedures for:
  110. ;     -- reloading fonts on standard EGA or VGA for
  111. ;     higher resolution text modes
  112. ;     -- enable HiColor mode of some Super VGAs
  113. ;     -- Handle the parameter passing conventions of the VESA BIOS
  114. ;     -- put VGA into 256 color plane mode ("MODE X")
  115. ;     -- etc...
  116. ;  There should be one entry in the table for every non-zero
  117. ;  'setup_procedure_index' in the text and graphics mode tables.
  118. ;  The first entry in the table belongs to index 100h, and so on.
  119. ;  The special setup procedure is invoked via a near call.
  120. ;
  121. ;  Entry: DI=address of the mode record from the text or graphics
  122. ;      table to set up.
  123. ;
  124. ;  Exit:  Adapter configured
  125. ;      BX=driver mode word as it should be returned by the mode set
  126. ;         routine. Typically it involves picking up the mode word
  127. ;         from the header and OR-ing in the appropriate bitplane mode
  128. ;         bitfield. (This is not needed for text modes)
  129. ;      AX, CX, DX, SI can be trashed, PRESERVE DI!!!!
  130. ;
  131. ;  NOTE: This runs in real mode, but don't mess with the segment registers.
  132. ;--------------------------------------------------------------------------
  133. special_setup_table    label word
  134.     dw    0    ; none here !!
  135.  
  136.  
  137. ;--------------------------------------------------------------------------
  138. ; DRIVER INIT ROUTINE
  139. ;  called once after the driver is loaded
  140. ;  may do one or more of the followings:
  141. ;    - check for proper board type
  142. ;    - check amount of RAM on board, and:
  143. ;    -- update word in header to reflect correct amount
  144. ;    -- disable modes in the tables for which there is not enough RAM
  145. ;    - check for special equipment (HiColor DAC, etc...)
  146. ;
  147. ;  Entry: nothing
  148. ;
  149. ;  Exit:  AX=status:
  150. ;       non-zero: OK,
  151. ;       0: something went wrong (e.g. wrong adapter, etc..)
  152. ;      BX,CX,DX may be trashed
  153. ;
  154. ;  NOTE: This runs in real mode, but don't mess with the segment registers.
  155. ;--------------------------------------------------------------------------
  156. driver_init_routine    proc    far
  157.     mov    ax,1
  158.     ret
  159. driver_init_routine    endp
  160.  
  161.  
  162. ;--------------------------------------------------------------------------
  163. ; MODE SET ROUTINE
  164. ;  sets up a text or graphics mode as close as possible to the one
  165. ;  reguested by the user with regard to number of colors and size.
  166. ;
  167. ;  Entry: AX=mode selection
  168. ;     0 = 80x25 text
  169. ;     1 = default text
  170. ;     2 = text CX cols by DX rows
  171. ;     3 = biggest text
  172. ;     4 = 320x200 graphics
  173. ;     5 = default graphics
  174. ;     6 = graphics CX width by DX height
  175. ;     7 = biggest non-interlaced graphics
  176. ;     8 = biggest graphics
  177. ;     9 = graphics BX colors, CX width by DX height
  178. ;
  179. ;  Exit: BX=driver mode flag
  180. ;     CX=width (in pixels or characters)
  181. ;     DX=height
  182. ;
  183. ;  NOTE: This runs in real mode, but don't mess with the segment registers.
  184. ;     YOU SHOULD NOT NEED TO CHANGE THIS ROUTINE AS IT IS PRETTY
  185. ;     MUCH TABLE DRIVEN
  186. ;--------------------------------------------------------------------------
  187. mode_set_routine    proc    far
  188.     push    ds
  189.     push    di
  190.     push    si
  191.     mov    si,cs
  192.     mov    ds,si
  193.     cmp    ax,9
  194.     jbe    DoIt
  195.     jmp    Exit
  196. DoIt:    add    ax,ax
  197.     mov    si,ax
  198.     jmp    WORD PTR mode_set_table[si]
  199. mode_set_table  label    word
  200.     dw    offset mode_0
  201.     dw    offset mode_1
  202.     dw    offset mode_2
  203.     dw    offset mode_3
  204.     dw    offset mode_4
  205.     dw    offset mode_5
  206.     dw    offset mode_6
  207.     dw    offset mode_7
  208.     dw    offset mode_8
  209.     dw    offset mode_9
  210. mode_0: mov    si,offset text_mode_table    ; 80x25 text
  211.     mov    bx,def_nc
  212.     mov    cx,80
  213.     mov    dx,25
  214.     jmp    Lookup
  215. mode_1: mov    si,offset text_mode_table    ; default text
  216.     mov    bx,def_nc
  217.     mov    cx,def_tw
  218.     mov    dx,def_th
  219.     jmp    Lookup
  220. mode_2: mov    si,offset text_mode_table    ; CX*DX text
  221.     mov    bx,def_nc
  222.     jmp    Lookup
  223. mode_3: mov    si,offset text_mode_table    ; biggest text
  224.     mov    bx,def_nc
  225.     mov    cx,Max_TW
  226.     mov    dx,Max_TH
  227.     jmp    Lookup
  228. mode_4: mov    si,offset graphics_mode_table    ; 320x200 graphics
  229.     mov    bx,def_nc
  230.     mov    cx,320
  231.     mov    dx,200
  232.     jmp    Lookup
  233. mode_5: mov    si,offset graphics_mode_table    ; default graphics
  234.     mov    bx,def_nc
  235.     mov    cx,def_gw
  236.     mov    dx,def_gh
  237.     jmp    Lookup
  238. mode_6: mov    si,offset graphics_mode_table    ; CX*DX graphics
  239.     mov    bx,def_nc
  240.     jmp    Lookup
  241. mode_7: mov    si,offset graphics_mode_table    ; biggest non-interlaced gr
  242.     mov    bx,def_nc
  243.     mov    cx,Max_GWn
  244.     mov    dx,Max_GHn
  245.     jmp    Lookup
  246. mode_8: mov    si,offset graphics_mode_table    ; biggest graphics
  247.     mov    bx,def_nc
  248.     mov    cx,Max_GW
  249.     mov    dx,Max_GH
  250.     jmp    Lookup
  251. mode_9: mov    si,offset graphics_mode_table    ; CX*DX graphics w/ BX colors
  252. ;
  253. ; At this point:
  254. ;   SI points to the table to search (text or graphics)
  255. ;   BX has colors
  256. ;   CX has width
  257. ;   DX has height
  258. ;
  259. Lookup: xor    ax,ax                ; last color number seen
  260. Find_C: cmp    [si+4],ax            ; last color number == this?
  261.     je    Same_C
  262.     jb    Prev_C                ; end of table -- use last color
  263.     cmp    BYTE PTR [si+6],0ffh        ; valid entry ?
  264.     je    Prev_C                ; not -- use last color
  265.     mov    ax,[si+4]            ; record color number
  266.     mov    di,si                ; start of entries w/ this color
  267.     cmp    ax,bx                ; enough colors ?
  268.     jae    Find_S
  269. Same_C: add    si,8
  270.     jmp    Find_C
  271. Prev_C: or    ax,ax                ; found any color at all?
  272.     je    Exit
  273. ;
  274. ; At this point:
  275. ;   DI points into the table to the first entry with the desired color
  276. ;      number (either it has enough colors or it is the highest color
  277. ;      number supported by the driver). Additionally, at least the
  278. ;      first (= smallest size) entry for this color is valid (has a
  279. ;      valid BIOS number).
  280. ;   AX has the color number adjusted for the driver
  281. ;   CX has width
  282. ;   DX has height
  283. ;
  284. Find_S: cmp    [di+4],ax            ; still the same color #?
  285.     jne    Prev_S
  286.     cmp    BYTE PTR [di+6],0ffh        ; valid entry ?
  287.     je    Prev_S
  288.     cmp    [di],cx
  289.     jb    Next_S
  290.     cmp    [di+2],dx
  291.     jae    GotIt
  292. Next_S: add    di,8
  293.     jmp    Find_S
  294. Prev_S: sub    di,8
  295. ;
  296. ; At this point:
  297. ;   DI points to the table entry we want to set up
  298. ;
  299. GotIt:  mov    ax,[di+6]            ; BIOS mode number
  300.     or    ah,ah                ; special ?
  301.     je    doBIOS
  302.     mov    al,ah
  303.     xor    ah,ah
  304.     dec    ax
  305.     add    ax,ax
  306.     mov    si,ax
  307.     call    WORD PTR special_setup_table[si]
  308.     jmp    RetVal
  309. doBIOS: int    10h
  310.     mov    bx,GRD_1_PLANE
  311.     cmp    WORD PTR [di+4],2        ; 2 colors ?
  312.     je    doFLAG
  313.     mov    bx,GRD_4_PLANES
  314.     cmp    WORD PTR [di+4],16        ; 16 colors ?
  315.     je    doFLAG
  316.     mov    bx,GRD_8_PLANES
  317.     cmp    WORD PTR [di+4],256        ; 256 colors ?
  318.     je    doFLAG
  319.     mov    bx,GRD_16_PLANES
  320.     cmp    WORD PTR [di+4],32768        ; 32K colors ?
  321.     je    doFLAG
  322.     mov    bx,GRD_PLANE_MASK        ; something is wrong!!
  323. doFLAG: or    bx,mode_W
  324. RetVal: mov    cx,[di]
  325.     mov    dx,[di+2]
  326. Exit:    pop    si
  327.     pop    di
  328.     pop    ds
  329.     ret
  330. mode_set_routine    endp
  331.  
  332.  
  333. ;--------------------------------------------------------------------------
  334. ; PAGING ROUTINE
  335. ;
  336. ;  Entry: AH=read page
  337. ;      AL=write page
  338. ;
  339. ;  Exit: VGA configured.
  340. ;     AX,BX,CX,DX,SI,DI may be trashed
  341. ;
  342. ;  NOTE: This runs in protected mode!  Don't mess with the segment registers!
  343. ;     This code must be relocatable and may not reference any data!
  344. ;--------------------------------------------------------------------------
  345.     assume  ds:nothing, es:nothing
  346.  
  347. paging_routine  proc    far
  348.     mov    cx,ax        ; save page
  349.     mov    dx,3ceh        ; set pagesize to 64k
  350.     mov    al,6
  351.     out    dx,al
  352.     inc    dx
  353.     in    al,dx
  354.     dec    dx
  355.     or    al,4
  356.     mov    ah,al
  357.     mov    al,6
  358.     out    dx,ax
  359.  
  360.     mov    dx,3c4h        ; switch to BPS mode
  361.     mov    al,0bh
  362.     out    dx,al
  363.     inc    dx
  364.     in    al,dx
  365.  
  366.     mov    ah,cl        ; output page
  367.     xor    ah,2
  368.     mov    al,0eh
  369.     mov    dx,3c4h
  370.     out    dx,ax
  371.  
  372.     mov    al,8        ; reconfig GR CTRL port for mask writes
  373.     mov    dx,3ceh
  374.     out    dx,al
  375.     ret
  376. paging_routine  endp
  377.  
  378.  
  379. cseg    ends
  380.     end
  381.  
  382.